package com.txt.config;

import com.txt.annotion.Update;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

// 自定义条件类
public class UpdateCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 获取环境变量
        Environment environment = context.getEnvironment();
        // 从 YML 配置中获取类型
        String paymentType = environment.getProperty("upload.type");
        // 获取注解中的类型
        String expectedType = (String) metadata.getAnnotationAttributes(Update.class.getName()).get("value");
        // 判断是否匹配
        return expectedType.equals(paymentType);
    }
}